const sqlite3 = require('sqlite3').verbose();
const path = require('path');

const dbPath = path.join(__dirname, 'data', 'pph.sqlite');
const db = new sqlite3.Database(dbPath);

console.log('🔍 检查目标值和预估值表结构...');

db.all("PRAGMA table_info(pph_targets)", (err, columns) => {
    if (err) {
        console.error('❌ 查询pph_targets表结构失败:', err);
    } else {
        console.log(`\n🎯 pph_targets表字段 (共${columns.length}个):`);
        columns.forEach(col => {
            console.log(`  ${col.cid}: ${col.name} (${col.type})`);
        });
    }
    
    db.all("PRAGMA table_info(pph_estimates)", (err2, columns2) => {
        if (err2) {
            console.error('❌ 查询pph_estimates表结构失败:', err2);
        } else {
            console.log(`\n📈 pph_estimates表字段 (共${columns2.length}个):`);
            columns2.forEach(col => {
                console.log(`  ${col.cid}: ${col.name} (${col.type})`);
            });
        }
        
        // 查看实际数据样本
        db.all("SELECT * FROM pph_targets LIMIT 2", (err3, targets) => {
            if (!err3) {
                console.log('\n🎯 pph_targets样本数据:');
                targets.forEach((row, i) => {
                    console.log(`  样本${i+1}:`, JSON.stringify(row));
                });
            }
            
            db.all("SELECT * FROM pph_estimates LIMIT 2", (err4, estimates) => {
                if (!err4) {
                    console.log('\n📈 pph_estimates样本数据:');
                    estimates.forEach((row, i) => {
                        console.log(`  样本${i+1}:`, JSON.stringify(row));
                    });
                }
                db.close();
            });
        });
    });
});
